In [3]:
category={'Sunflower':'http://www.image-net.org/api/text/imagenet.synset.geturls?wnid=n11978961',
'Peony':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11719286',
'Nigella':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11736851',
'Spathiphyllum':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11792341',
'Ragged_robin':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11811706',
'Soapwort':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11814584',
'Ice_plant':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11821184',
'Spring_beauty':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11859472',
'African_daisy':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11925303',
'Cornflower':'http://image-net.org/api/text/imagenet.synset.geturls?wnid=n11947802'
}
In [ ]:
In [4]:
import cv2
import os
import urllib.request
from urllib.request import Request, urlopen
from urllib.error import URLError
import socket
socket.setdefaulttimeout(1)
In [5]:
def get_urls(urls_links):
url_list=urllib.request.urlopen(urls_links).read().decode().split('\r\n')
return url_list
In [6]:
def download_images(urls_link,category_name):
if not os.path.exists(category_name):
os.makedirs(category_name)
count=1
url_list=get_urls(urls_link)
for url in url_list:
try:
path_name=str(category_name)+'/'+str(count)+'.'+str(category_name)+'.jpg'
urllib.request.urlretrieve(url,path_name)
img=cv2.imread(path_name)
resized_image=cv2.resize(img,(100,100))
cv2.imwrite(path_name,resized_image)
except Exception as e:
print(str(count)+str(e))
count+=1
In [ ]:
for cate in category:
download_images(category['cate'],cate)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: